(function(jQuery) {
	/*
	 * 驾驶员查询放大镜JS插件
	 */

	var gridColMenu_Detail = null;

	$.MagnifierJSYUtils = {
		/**
		 * 页面初始化函数
		 */
		init : function() {
			var name = encodeURI($('#condition').val());
			var carrierCode = $('#magnifierJSYPage_i_carrierCode').val();
			var magniferType = $('#magnifierJSYPage_i_magniferType').val();
			var editFlag = $('#magnifierJSYPage_i_editFlag').val();
			var driverId = $('#magnifierJSYPage_i_driverId').val();
			// 创建列表DataGrid
			$('#magnifierJSYPage_jsy')
					.datagrid(
							{
								url : 'magnifier/getMagnifierJSYList.do?catch='
										+ new Date() 
										+ '&name='
										+ name
										+ '&carrierCode='
										+ carrierCode
										+ '&magniferType='
										+ magniferType
										+ '&editFlag='
										+ editFlag
										+ '&driverId='
										+ driverId
										+ '&Login_SessionId=' + sessionId,
								method : 'get',
								title : $.i18n.prop("js.magnifier.title.jsy"),
								iconCls : 'icon-large-smartart',
								pagination : true,
								rownumbers : true,
								striped : true,
								pageSize : 10,
								pageList : [10],
								columns : [ [ {
									field : 'id',
									title : $.i18n.prop("js.magnifier.datagrid.id"),
									hidden : true,
									width : 0,
									align : 'left'
								}, {
									field : 'name',
									title : $.i18n.prop("js.magnifier.datagrid.xm"),
									width : 200,
									align : 'left'
								} , {
									field : 'contact',
									title : $.i18n.prop("js.magnifier.datagrid.lxfs"),
									width : 233,
									align : 'left'
								} ] ],

								onDblClickRow : function(rowIndex, rowData) {
									//向父页面赋值
									if ($('#magnifierJSYPage_clickflag').val() != null && $('#magnifierJSYPage_clickflag').val().length > 0) {
										$("#" + $('#magnifierJSYPage_clickflag').val()).val('0');
									}
									if ($('#magnifierJSYPage_id').val() != null && $('#magnifierJSYPage_id').val().length > 0) {
										$("#" + $('#magnifierJSYPage_id').val()).val(rowData.id);
									}
									if ($('#magnifierJSYPage_name').val() != null && $('#magnifierJSYPage_name').val().length > 0) {
										$("#" + $('#magnifierJSYPage_name').val(),
												window.parent.document).searchbox(
												'setValue', rowData.name);
									}
									if ($('#magnifierJSYPage_contact').val() != null && $('#magnifierJSYPage_contact').val().length > 0) {
										$("#" + $('#magnifierJSYPage_contact').val(),
												window.parent.document).textbox(
												'setValue', rowData.contact);
									}
									
									//关闭放大镜窗口
									$("#magnifier_window").window('close');
								},
								onLoadError: function(){
									$.LmisUtils.opLoadError();
								}
							});
			
			/**
			 * 联想输入
			 */
			    $('#condition').autocomplete({
			    	serviceUrl: 'magnifier/getJSYByName.do?carrierCode='+carrierCode+'&catch='
					+ new Date()+ '&magniferType='
					+ magniferType
					+ '&editFlag='
					+ editFlag
					+ '&driverId='
					+ driverId
					+ '&Login_SessionId=' + sessionId,
			    	paramName: "name",
			    	transformResult: function(response) {
			        return {
			            suggestions: $.map($.parseJSON(response), function(item) {
			                return { value: item, data: item };
			            })
			        };
			    }
			});    

		},

		/**
		 * 查询
		 */
		search : function() {
			var name = encodeURI($('#condition').val());
			var carrierCode = $('#magnifierJSYPage_i_carrierCode').val();
			var magniferType = $('#magnifierJSYPage_i_magniferType').val();
			var editFlag = $('#magnifierJSYPage_i_editFlag').val();
			var driverId = $('#magnifierJSYPage_i_driverId').val();
			$('#magnifierJSYPage_jsy')
					.datagrid(
							{
								url : 'magnifier/getMagnifierJSYList.do?catch='
									+ new Date() 
									+ '&name='
									+ name
									+ '&carrierCode='
									+ carrierCode
									+ '&magniferType='
									+ magniferType
									+ '&editFlag='
									+ editFlag
									+ '&driverId='
									+ driverId
									+ '&Login_SessionId=' + sessionId
							});
		}
	};
})(jQuery);
$.MagnifierJSYUtils.init();
